<template>
    <div class="mainBox">
        <div class="center">
            <button
                    v-for="(item, index) in btnList"
                    :key="index"
                    @click="callBack(item.method)"
                    class="btn custom-btn btn-3"
            >
                <span>{{ item.label }}</span>
            </button>
        </div>
    </div>
</template>

<script>
export default {
    name: "index",
    props: {
        data: {
            type: Object,
            default: {}
        }
    },
    data() {
        return {
            btnList: [
                {
                    label: "上一个",
                    method: "last",
                },
                {
                    label: "下一个",
                    method: "next",
                },
            ],
            index: 1,
        };
    },
    mounted() {
    },
    methods: {
        last() {
            console.log(this.data)
            if (this.data.index === 1){
                this.index = this.data.total
            }else {
                this.index = this.data.index - 1
            }
            console.log('去上一个demo')
            const url = 'ChallengeDay' + this.index
            this.$router.push({name: url,params:{total:this.data.total,index:this.index}})
        },
        next() {
            if (this.data.index === this.data.total){
                this.index = 1
            }else {
                this.index = this.data.index + 1
            }
            const url = 'ChallengeDay' + this.index
            console.log(url)
            this.$router.push({name: url,params:{total:this.data.total,index:this.index}})
        },
        callBack(method) {
            this[method]();
        },
    },
}
</script>

<style scoped>
.mainBox {
    position: absolute;
    top: 70%;
    left: 50%;
}

.center {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
}

.btn {
    background: #009fe9;
    color: #fff;
    border: none;
    padding: 6px;
    width: 100px;
    border-radius: 4px;
    display: inline-block;
    margin-right: 10px;
}

.custom-btn {
    width: 130px;
    height: 40px;
    color: #fff;
    border-radius: 5px;
    padding: 10px 25px;
    font-family: 'Lato', sans-serif;
    font-weight: 500;
    background: transparent;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    display: inline-block;
    box-shadow: inset 2px 2px 2px 0px rgba(255, 255, 255, .5),
    7px 7px 20px 0px rgba(0, 0, 0, .1),
    4px 4px 5px 0px rgba(0, 0, 0, .1);
    outline: none;
}

/* 3 */
.btn-3 {
    background: rgb(0, 172, 238);
    background: linear-gradient(0deg, rgba(0, 172, 238, 1) 0%, rgba(2, 126, 251, 1) 100%);
    width: 130px;
    height: 40px;
    line-height: 42px;
    padding: 0;
    border: none;

}

.btn-3 span {
    position: relative;
    display: block;
    width: 100%;
    height: 100%;
}

.btn-3:before,
.btn-3:after {
    position: absolute;
    content: "";
    right: 0;
    top: 0;
    background: rgba(2, 126, 251, 1);
    transition: all 0.3s ease;
}

.btn-3:before {
    height: 0%;
    width: 2px;
}

.btn-3:after {
    width: 0%;
    height: 2px;
}

.btn-3:hover {
    background: transparent;
    box-shadow: none;
}

.btn-3:hover:before {
    height: 100%;
}

.btn-3:hover:after {
    width: 100%;
}

.btn-3 span:hover {
    color: rgba(2, 126, 251, 1);
}

.btn-3 span:before,
.btn-3 span:after {
    position: absolute;
    content: "";
    left: 0;
    bottom: 0;
    background: rgba(2, 126, 251, 1);
    transition: all 0.3s ease;
}

.btn-3 span:before {
    width: 2px;
    height: 0%;
}

.btn-3 span:after {
    width: 0%;
    height: 2px;
}

.btn-3 span:hover:before {
    height: 100%;
}

.btn-3 span:hover:after {
    width: 100%;
}
</style>